﻿using DeZhen.Core.Framework.Config;
using DeZhen.Core.Framework.Entity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace DeZhen.Core.SqlSugar.Service
{
    [Service(ServiceLifetime.Singleton)]
    public class SqlSugarPlatform
    {
        List<ConnectionConfig> ListConnectionConfig = AppConfig.GetSection("DBConfig").Get<List<ConnectionConfig>>();
        public SqlSugarScope SqlClient { get; set; }
        public SqlSugarPlatform()
        {
            InitializeRegisterSqlConfig();
        }
        private void InitializeRegisterSqlConfig()
        {
            ListConnectionConfig.ForEach(config =>
            {
                config.IsAutoCloseConnection = true;
                config.MoreSettings = new ConnMoreSettings()
                {
                    IsWithNoLockQuery = true,
                };
            });
            SqlClient = new SqlSugarScope(ListConnectionConfig);
        }
      
    }
}
